{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f0ba8059",
   "metadata": {},
   "source": [
    "# 常用内置函数\n",
    "\n",
    "## 数值相关\n",
    "\n",
    "绝对值`abs()`："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4fc52318",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.2"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "abs(-1.2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1d600c1d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.0"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "abs(3 + 4j)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b97f5ee2",
   "metadata": {},
   "source": [
    "商和余数的计算`divmod()`函数："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "589b2600",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 2)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "divmod(12, 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5abba371",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4.0, 0.2999999999999998)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "divmod(2.3, 0.5)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "9c83fed8",
   "metadata": {},
   "source": [
    "幂的计算`pow()`函数："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f6be29bd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1125899906842624"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pow(2, 50)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "61dee102",
   "metadata": {},
   "source": [
    "还可以给定第三个参数，计算幂次模第三个参数的结果："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "93a6b03c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2624"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pow(2, 50, 10000)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "854a2d8d",
   "metadata": {},
   "source": [
    "近似值的计算`round()`函数："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "bfbfabc7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(12.31)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "7f96fd92",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12.3"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(12.314, 1)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "07daaeae",
   "metadata": {},
   "source": [
    "## 序列相关"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd6774c7",
   "metadata": {},
   "source": [
    "序列的最值`max()`和`min()`函数："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c7fdb392",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max(1, 2, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "dde130d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "min(1, 2, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "4f0de093",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max([1, 2, 3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "667b7552",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "min([1, 2, 3])"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "43a54265",
   "metadata": {},
   "source": [
    "序列元素的真假判断`all()`、`any()`："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6e4aac80",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "all([1,2,3,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "2d5c7956",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "any([1,2,3,0])"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "14c59780",
   "metadata": {},
   "source": [
    "序列的和`sum()`："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "fee11396",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum([1,2,3,4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43356d86",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
